﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.Record;


namespace TyMES.ViewModel.Record.AlarmLogRecordVMs
{
    public partial class AlarmLogRecordListVM : BasePagedListVM<AlarmLogRecord_View, AlarmLogRecordSearcher>
    {

        protected override IEnumerable<IGridColumn<AlarmLogRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<AlarmLogRecord_View>>{
                this.MakeGridHeader(x => x.warningTime),
                this.MakeGridHeader(x => x.lineCode),
                this.MakeGridHeader(x => x.stationCode),
                this.MakeGridHeader(x => x.operationCode),
                this.MakeGridHeader(x => x.machineCode),
                this.MakeGridHeader(x => x.warningCode),
                this.MakeGridHeader(x => x.warningType),
                this.MakeGridHeader(x => x.warningDesc),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<AlarmLogRecord_View> GetSearchQuery()
        {
            var query = DC.Set<AlarmLogRecord>()
                .CheckBetween(Searcher.warningTime?.GetStartTime(), Searcher.warningTime?.GetEndTime(), x => x.warningTime, includeMax: false)
                .CheckContain(Searcher.lineCode, x=>x.lineCode)
                .CheckContain(Searcher.stationCode, x=>x.stationCode)
                .CheckContain(Searcher.operationCode, x=>x.operationCode)
                .CheckContain(Searcher.machineCode, x=>x.machineCode)
                .CheckContain(Searcher.warningCode, x=>x.warningCode)
                .CheckContain(Searcher.warningType, x=>x.warningType)
                .CheckContain(Searcher.warningDesc, x=>x.warningDesc)
                .Select(x => new AlarmLogRecord_View
                {
				    ID = x.ID,
                    warningTime = x.warningTime,
                    lineCode = x.lineCode,
                    stationCode = x.stationCode,
                    operationCode = x.operationCode,
                    machineCode = x.machineCode,
                    warningCode = x.warningCode,
                    warningType = x.warningType,
                    warningDesc = x.warningDesc,
                })
                .OrderByDescending(x => x.ID);
            return query;
        }

    }

    public class AlarmLogRecord_View : AlarmLogRecord{

    }
}
